//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace.b;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public final class j implements b {
    private Socket a = null;
    private DataOutputStream b = null;

    private j() {
    }

    protected static j e() {
        return new j();
    }

    public final void a(e var1) {
        try {
            this.a = new Socket();
            this.a.connect(new InetSocketAddress("gateway.yingyan.baidu.com", 8300), 8000);
            this.a.setKeepAlive(true);
            if(!this.b()) {
                var1.b();
                return;
            }

            var1.a();
        } catch (Exception var2) {
            if(a.a == com.baidu.trace.b.a.a()) {
                var1.b();
            }

            return;
        } catch (Throwable var3) {
            if(a.a == com.baidu.trace.b.a.a()) {
                var1.b();
            }
        }

    }

    public final void a() {
        try {
            if(this.b != null) {
                this.b.close();
            }

            if(this.a != null && !this.a.isClosed()) {
                this.a.close();
            }

            return;
        } catch (Exception var4) {
            ;
        } finally {
            this.b = null;
            this.a = null;
        }

    }

    public final boolean b() {
        return this.a == null?false:this.a.isConnected() && !this.a.isClosed() && !this.a.isInputShutdown() && !this.a.isOutputShutdown();
    }

    public final int c() {
        return this.a != null?this.a.getLocalPort():0;
    }

    public final void a(byte[] var1) throws IOException {
        if(this.b == null) {
            this.b = new DataOutputStream(this.a.getOutputStream());
        }

        if(var1 != null) {
            this.b.write(var1);
            this.b.flush();
        }

    }

    public final InputStream d() throws IOException {
        return this.a.getInputStream();
    }
}
